<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>就诊人管理</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.2.3/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.2.3/js/bootstrap.bundle.min.js"></script>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <link rel="stylesheet" href="/stylesheets/common.css">
    <style>
        .bg {
            height: 150px;
            background-color: rgb(64, 176, 224);
            position: relative;
        }

        .header {
            background-color: white;
            border-radius: 30px;
            height: 180px;
            position: absolute;
            width: 94%;
            top: 40px;
        }

        .part {
            position: absolute;
            height: 200px;
            top: 260px;
            width: 100%;
        }

        .headimg {
            border-radius: 50%;
            position: absolute;
            top: -25px;
            left: 40%;
            border: 5px solid white;
        }

        p {
            margin-bottom: 0;
        }

        .input-group {
            border: none;
        }

        .alert_ {
            display: none;
        }
    </style>
</head>

<body>
    <div class="bg"></div>
    <div class="container">
        <div class="header mt-4 px-3 ">
            <div>
                <img class="headimg " src="./images/manimg.png" width="70px" height="70" alt="">
            </div>
            <div class="input-group mb-3 mt-5">
                <span class="input-group-text " id="inputGroup-sizing-default">姓名</span>
                <input type="text" class="form-control" aria-label="Sizing example input"
                    aria-describedby="inputGroup-sizing-default" id="inpname">
            </div>
            <div class="input-group mb-3 ">
                <span class="input-group-text" id="inputGroup-sizing-default">身份证号</span>
                <input type="text" class="form-control" aria-label="Sizing example input"
                    aria-describedby="inputGroup-sizing-default" id="inpidcard">
            </div>
        </div>
        <div class="part">
            <div class="ms-3 mt-4">
                <p style="color: orange;">温馨提示</p>
                <p>请输入正确的姓名和身份证号</p>
            </div>
            <div class="mt-3">
                <button type="button" class="btn btn-primary mt-4 addbtn" style="width: 94%;">确认</button>
            </div>
            <div class="alert alert-danger alert_ mt-4" role="alert">
                请检查姓名和身份证号是否全部输入！
            </div>
        </div>
    </div>
    <script>
        $('.addbtn').click(function () {
            if ($('#inpname').val() != '' &&
                $('#inpidcard').val() != '') {
                $.ajax({
                    method: 'get',
                    url: 'http://localhost:3000/patient/add',
                    data: {
                        "name": $('#inpname').val(),
                        "idcard": $('#inpidcard').val(),
                    },
                    success: function (data) {
                        console.log(data)
                        if (data.code == 0) {
                            alert(data.msg)
                            location.href='/patient.html'
                        } else {
                            alert(data.msg)
                        }
                    },
                    error: function (e) {
                        console.log(JSON.stringify(e));
                    }
                })
            } else {
                $('.alert_').slideDown();
                setTimeout(() => {
                    $('.alert_').slideUp();
                }, 2000)
            }
        })


    </script>
</body>

</html>